package com.situ.mall.service;

import com.situ.mall.common.util.JsonUtil;
import com.situ.mall.common.util.RedisUtil;
import com.situ.mall.pojo.entity.Category;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Scanner;

// 实现InitializingBean接口的类会在启动时自动调用。
@Component
public class Init implements InitializingBean {
    @Autowired
    private ICategoryService categoryService;

    @Autowired
    private RedisUtil redisUtil;


    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("Init.afterPropertiesSet");
        List<Category> list = categoryService.selectTopCategoryList();
        String topCategoryListJson = JsonUtil.objectToJson(list);
        redisUtil.set("topCategoryListJson", topCategoryListJson);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[][] array;
        String str = "";
        System.out.println("请输入字符串，输入q退出");
        while (true) {
            String temp = scanner.next();
            if ("q".equals(temp)) {
                break;
            }
            str = str + temp + ";";
        }
        if ("".equals(str)) {
            System.out.println("字符串不能为空");
            return;
        }
        // str = 1,25,6;34,6,7
        String[] first = str.split(";");
        array = new int[first.length][];
        for (int i = 0; i < first.length; i++) {
            String[] second = first[i].split(",");
            array[i] = new int[second.length];
            for (int j = 0; j < second.length; j++) {
                array[i][j] = Integer.parseInt(second[j]);
            }
        }

        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[i].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
}
